package com.onenine.app.activity;

import android.support.v7.widget.RecyclerView;
import android.util.Pair;

import com.onenine.app.R;
import com.onenine.app.adapter.ConsumeAdapter;
import com.onenine.app.request.PageRequest;
import com.onenine.app.response.ConsumeDetailResponse;
import com.onenine.app.utils.UrlConfig;
import com.onenine.base.base.BasePageListActivity;
import com.onenine.base.okhttp.OkCallback;
import com.onenine.base.okhttp.OkRequest;
import com.onenine.base.utils.AppConfig;
import com.onenine.base.view.PullRefreshRecyclerView;
import com.onenine.chat.rongcloud.RcUser;

/**
 * 消费记录
 */
public class ConsumeListActivity extends BasePageListActivity {

    @Override
    protected Pair<PullRefreshRecyclerView, RecyclerView.Adapter> initPullRefreshView() {
        return Pair.create(findViewById(R.id.pull_to_refresh_layout), new ConsumeAdapter());
    }

    @Override
    protected void initViews() {
        super.initViews();
        mToolbar.setCenterTitle(R.string.consume_record);
        loadPageData(1);
    }

    @Override
    protected void loadPageData(int pageNum) {
        PageRequest request = new PageRequest();
        request.setUserId(RcUser.getInstance().getUserId());
        request.setPageNum(pageNum);
        request.setPageSize(AppConfig.PAGE_SIZE);
        OkRequest.getInstance().withUrl(UrlConfig.GET_CONSUME_DETAIL)
                .withRequest(request).doRequest(getClass().getSimpleName(), new OkCallback<ConsumeDetailResponse>() {
            @Override
            public void onResponse(ConsumeDetailResponse response, String srcData) {
                dismissRefreshStatus();
                if (response.isSuccess()) {
                    notifyDataSuccess(response.getConsumeDetailItemList());
                } else {
                    notifyDataFailure();
                }
            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_pull_refresh_layout;
    }

}
